package com.manage.action;


import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.manage.po.Room;
import com.manage.service.IRoomService;
import com.manage.util.PagerModel;


@Controller
@Results({
		@Result(name = "room_list", location = "systemAdmin/room/roomManage.jsp"),
		@Result(name = "room_edit", location = "systemAdmin/room/roomEdit.jsp"),
		@Result(name = "room_list_lookup", location = "systemAdmin/room/room_list_lookup.jsp"),
		@Result(name = "error", location = "error.jsp") })
public class RoomAction extends BaseAction{
	
	private static final long serialVersionUID = 6718838822334455667L;
	@Autowired
	private IRoomService roomService;
	
	private PagerModel pm;
	private int pageNum = 1;
	private int numPerPage = 20;
	private String[] ids;   //删除ID
	
	
	private String roomid;
	//查找内容
	private String searchRoomID;
	private String searchRoomName;
	private String searchLeader;
		
	private String room_id;   //修改id 
	private String editorType;
	
	private Room room;


    ////////////////////////////////////////////////////////////////////////////////
		
	@Action("roommanage")
	public String getRoomList(){
		//pm=roomService.getRoomById(roomid, pageNum, numPerPage);
		pm = roomService.search(searchRoomID, searchRoomName,searchLeader, pageNum, numPerPage);
		return "room_list";
	}
	
	@Action("SearchRoom_List")
	public String search(){
		System.out.println(searchRoomID + "***" + searchRoomName + "***" +searchLeader);	
		pm = roomService.search(searchRoomID, searchRoomName,searchLeader, pageNum, numPerPage);
		return "room_list";
	}
	
	
	// 用于查找带回
	@Action("Room_List_LookUp")
	public String room_list_lookup(){
		pm = roomService.search(searchRoomID, searchRoomName,searchLeader, pageNum, numPerPage);
		return "room_list_lookup";
	}
	
	
	//////////////////////////////////////////////////////////
	@Action("Room_Add")
	public String toAddRoomInfo() {
		editorType="add";
		return "room_edit";
	}
		
	@Action("Room_Modify")
	public String showModify(){
		System.out.println("---------777777777----------");
		editorType="modify";
		room = roomService.getRoomById(room_id);
		return "room_edit";	
	}

	@Action("Room_Save")
	public String save(){
		try{
			if(editorType.equals("add")){
				roomService.save(room);
				return ajaxJsonSuccessMessage("您已经添加成功!","ROOMMANAGE","closeCurrent");
			}else{
				roomService.merge(room);
				return ajaxJsonSuccessMessage("您已经修改成功!","ROOMMANAGE","closeCurrent");
			}
		}catch(Exception e){
			return ajaxJsonWarningMessage("该房间号已重复！");
		}
	}
	
	///////////////////////////////////////////////////////////////	
	@Action("Room_BatchDelete")
	public String delete(){
		roomService.batchDelete(ids);
		return ajaxJsonSuccessMessage("删除成功","","");
	}

	public IRoomService getRoomService() {
		return roomService;
	}

	public void setRoomService(IRoomService roomService) {
		this.roomService = roomService;
	}

	public PagerModel getPm() {
		return pm;
	}

	public void setPm(PagerModel pm) {
		this.pm = pm;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getNumPerPage() {
		return numPerPage;
	}

	public void setNumPerPage(int numPerPage) {
		this.numPerPage = numPerPage;
	}

	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public String getRoomid() {
		return roomid;
	}

	public void setRoomid(String roomid) {
		this.roomid = roomid;
	}

	public String getSearchRoomID() {
		return searchRoomID;
	}

	public void setSearchRoomID(String searchRoomID) {
		this.searchRoomID = searchRoomID;
	}

	public String getSearchRoomName() {
		return searchRoomName;
	}

	public void setSearchRoomName(String searchRoomName) {
		this.searchRoomName = searchRoomName;
	}

	public String getSearchLeader() {
		return searchLeader;
	}

	public void setSearchLeader(String searchLeader) {
		this.searchLeader = searchLeader;
	}

	public String getRoom_id() {
		return room_id;
	}

	public void setRoom_id(String room_id) {
		this.room_id = room_id;
	}

	public String getEditorType() {
		return editorType;
	}

	public void setEditorType(String editorType) {
		this.editorType = editorType;
	}

	public Room getRoom() {
		return room;
	}

	public void setRoom(Room room) {
		this.room = room;
	}


}
	
	